from app.db.crud import CRUD
from app.db.sqlalchemy import AsyncSession
from app.db.models import FidbackModel

from app.shemas.shemas import FidbackCreate, Fidback


class FidbackRepo:
    def __init__(self, session: AsyncSession):
        self._crud = CRUD(session=session, cls_model=FidbackModel)

    async def create_task(self, fidback_in_creation: FidbackCreate) -> Fidback:
        model_data = {
            "division": fidback_in_creation.division,
            "subdivision": fidback_in_creation.subdivision,
            "description": fidback_in_creation.discription,
        }
        row = await self._crud.create(model_data=model_data)

        fidback_in_db = await self._crud.get(pkey_val=row.id)

        return self._to_domain(fidback_in_db)

    async def get_task(self, fidback_id: int) -> Fidback:
        fidback_in_db = await self._crud.get(pkey_val=fidback_id)
        return self._to_domain(fidback_in_db)
